package com.lewin;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.*;

/**
 * Servlet implementation class Insert
 */
@WebServlet("/Insert")
public class Insert extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Insert() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 String MaMH = request.getParameter("MaMH");
		 String TenMH = request.getParameter("TenMH");
		 String LoaiMH = request.getParameter("LoaiMH");
		 double DonGia = Double.parseDouble(request.getParameter("DonGia"));
		 String Hinh = request.getParameter("Hinh");
		 
		 SanPham sp = new SanPham(MaMH, TenMH, LoaiMH, DonGia,Hinh);
		 ConnectDB db = new ConnectDB();
		 try {
		 if(db.insertNew(sp))
		 response.sendRedirect("index.jsp");
		 else
		 response.sendRedirect("error.jsp");
		 } catch (Exception e) {
		 // TODO Auto-generated catch block
		 e.printStackTrace();
		 }
}

	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
